package com.xinqi.modules.user.users.user.controller.admin;


import com.xinqi.common.log.syslog.annotation.Log;
import com.xinqi.common.log.syslog.enums.BusinessType;
import com.xinqi.common.log.syslog.enums.OperatorType;
import com.xinqi.modules.user.user.dto.req.UpdateUsersStatusDTO;
import com.xinqi.modules.user.user.dto.req.UserQueryDTO;
import com.xinqi.modules.user.user.dto.req.UsersSetAdminDTO;
import com.xinqi.modules.user.user.dto.rsp.UserResultDTO;
import com.xinqi.common.base.constants.ServiceNameConstants;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.user.users.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息Admin控制层
 *
 * @author: wenjie
 * @date: 2023/05/17
 */
@Tag(name = "Admin-用户信息", description = "用户信息Admin接口")
@RestController
@RequestMapping("/admin/user")
@RequiredArgsConstructor
public class UserAdminController {
    private final UserService userService;

    /**
     * 用户信息-分页
     */
    @Operation(summary = "用户信息-分页")
    @GetMapping("/page")
    public R<PageInfo<UserResultDTO>> page(@ParameterObject UserQueryDTO dto) {
        return R.data(userService.pageAdmin(dto, dto));
    }

    /**
     * 用户信息-详情
     */
    @Operation(summary = "用户信息-详情")
    @GetMapping("/{userId}")
    public R<UserResultDTO> getInfo(@PathVariable("userId") Long userId) {
        return R.data(userService.selectAdminById(userId));
    }

    /**
     * 修改用户信息
     */
    @Operation(summary = "更新用户状态")
    @PutMapping("/update-status")
    @Log(title = ServiceNameConstants.XQ_AUTH + " -- 更新用户状态", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R<Boolean> updateStatus(@RequestBody UpdateUsersStatusDTO dto) {
        return R.data(userService.updateStatus(dto));
    }

    /**
     * 设置管理员
     */
    @Operation(summary = "设置管理员")
    @PutMapping("/set-admin")
    @Log(title = ServiceNameConstants.XQ_AUTH + " -- 设置管理员", businessType = BusinessType.GRANT, operatorType = OperatorType.MANAGE)
    public R<Boolean> setAdmin(@RequestBody UsersSetAdminDTO dto) {
        return R.data(userService.setAdmin(dto));
    }
}
